package com.qf.agro.web.controller.facilities;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.qf.agro.common.sys.ResultInfo;
import com.qf.agro.pojo.facilities.Facilities;
import com.qf.agro.service.facilities.FacilitiesService;
import com.qf.agro.vo.OptionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @company：千锋教育
 * @author：zhy
 * @date：2023/7/3
 */
@RestController
@RequestMapping("/facilities/facilities")
public class FacilitiesController {

    @Autowired
    private FacilitiesService facilitiesService;

    /**
     * 分页查询农业设施分类
     * @param pageNum
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public ResultInfo findPage(@RequestParam(value = "page",defaultValue = "1") Integer pageNum,
                               @RequestParam(defaultValue = "5") Integer pageSize,
                               String name){
        //1.调用业务层查询
        Page<Facilities> page = facilitiesService.findPage(pageNum, pageSize, name);
        //2.返回
        return ResultInfo.success(page);
    }


    /**
     * 新增分类
     * @param facilities
     * @return
     */
    @PostMapping
    public ResultInfo save(@RequestBody Facilities facilities){
        //1.调用业务层新增
        facilitiesService.save(facilities);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 修改分类
     * @param facilities
     * @return
     */
    @PutMapping
    public ResultInfo update(@RequestBody Facilities facilities){
        //1.调用业务层
        facilitiesService.update(facilities);
        //2.返回
        return ResultInfo.success(null);
    }

    /**
     * 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public ResultInfo delete(Long id){
        //1.调用业务层删除
        facilitiesService.delete(id);
        //2.返回
        return ResultInfo.success(null);
    }

    @GetMapping("/selectOptions")
    public ResultInfo selectOptions(){
      List<OptionVo> facilities= facilitiesService.findOptions();
      return ResultInfo.success(facilities);
    }
}
